@echo off
setlocal enabledelayedexpansion

rem 设置基础路径
set "WORKSPACE=%~dp0"
set "LUBAN_DLL=%WORKSPACE%..\..\Tools\Luban\Luban.dll"
set "CustomTemplates=%WORKSPACE%..\..\Tools\CustomTemplates"
set "ValidationVersion=%WORKSPACE%"

rem 获取 dotnet 路径参数（若外部传入）
set "DotnetPath=%1"

rem 输出日志（模拟 Bash 的日期格式）
echo %date:/=-% %time:~0,8%.000^|INFO^| ==========================================================================================
echo %date:/=-% %time:~0,8%.001^|INFO^| Validation! PATH: %ValidationVersion%

rem 检查 dotnet 路径是否为空
if "%DotnetPath%"=="" (
    set "DotnetPath=dotnet"
) else (
    echo %date:/=-% %time:~0,8%.002^|INFO^| Use given dotnet path: %DotnetPath%
)

rem 执行 Luban 命令
%DotnetPath% %LUBAN_DLL% ^
    --conf "%WORKSPACE%luban.conf" ^
    --customTemplateDir "%CustomTemplates%" ^
    --validationFailAsError true ^
    -t all ^
    -f

rem 记录退出码并验证结果
set "LubanExitCode=%ERRORLEVEL%"
echo %date:/=-% %time:~0,8%.000^|INFO^| LubanExitCode: %LubanExitCode%

if %LubanExitCode% equ 0 (
    echo %date:/=-% %time:~0,8%.000^|INFO^| Validation Success! Success! Success!
    exit /b 0
) else (
    echo %date:/=-% %time:~0,8%.000^|ERROR^| Validation Failed! Failed! Failed!
    exit /b 1
)